package cate.game.event.rank;

import cate.game.GameBody;
import cate.game.event.GameEventListener;
import cate.game.framework.ThreadShare;
import cate.game.rank.po.Rank;

public class RewardRankChangeListener implements GameEventListener<RewardRankChangeEvent> {
    @Override
    public void onEvent(RewardRankChangeEvent gameEvent) {
        GameBody gameBody = gameEvent.gameBody;
        int rankId = gameEvent.rankId;
        if(rankId == 0 || !gameBody.table.rank.hasReward(rankId)){
            return;
        }
        long leastRankValue = gameBody.table.rank.getLeastValue(rankId);
        Rank rank = gameEvent.rank;
        if(rank != null && rank.value >= leastRankValue){
            gameBody.rank.data.record(rankId, rank);
            if (!ThreadShare.almostFull()) {
                gameBody.role.activeForOnlineSelfThread(role -> role.getFarm().rank.noticeUpdate(rankId));
            }
        }
    }
}
